package com.locationbasedagent;

import java.util.ArrayList;
import java.util.List;

import android.app.Activity;
import android.os.AsyncTask;

import com.google.web.bindery.requestfactory.shared.Receiver;
import com.locationbasedagent.shared.HouseListingProxy;
import com.locationbasedagent.shared.LocationBasedAgentRequestFactory;
import com.locationbasedagent.shared.LocationBasedAgentUserProxy;


public class AsyncFetchUserTask extends AsyncTask<String, Void, List<LocationBasedAgentUserProxy>> {

    private AsyncFetchUserDelegate activity;

    public AsyncFetchUserTask(AsyncFetchUserDelegate activity) {
        super();
        this.activity = activity;
    }

    @Override
    protected List<LocationBasedAgentUserProxy> doInBackground(String... arguments) {
        final List<LocationBasedAgentUserProxy> list = new ArrayList<LocationBasedAgentUserProxy>();

        // INSERT RPC HERE!
        LocationBasedAgentRequestFactory request = Util.getRequestFactory((Activity)activity, LocationBasedAgentRequestFactory.class);
        
       
        	//queryHouseListings param: address, city, zip, radius
	        request.listingRequest().queryLocationBasedAgentUsersByID(arguments[0]).fire(new Receiver<List<LocationBasedAgentUserProxy>>() {
				@Override
				public void onSuccess(List<LocationBasedAgentUserProxy> arg0) {
					list.addAll(arg0);
				}
	        });


        return list;
    }

    @Override
    protected void onPostExecute(List<LocationBasedAgentUserProxy> result) {
    		activity.updateUserList(result);
    	
    }
}
